options(stringsAsFactors = F)
setwd("/Volumes/FileManage/0660Drive/02.heterosis_project/08133BtGroup/03.WGCNA/leaf_result/")
BtJ <- read.delim("/Volumes/FileManage/0660Drive/02.heterosis_project/04.RawData/fpkmMerge/Bt_x_J._L.xls",
                  header = T,
                  sep = "\t")
BtSY <- read.delim("/Volumes/FileManage/0660Drive/02.heterosis_project/04.RawData/fpkmMerge/Bt_x_SY._L.xls",
                   header = T,
                   sep = "\t")


clean <- data.frame(GID = BtJ$transcript_id,
                    Bt = BtJ$Bt_L_FPKM,
                    J = BtJ$J_L_FPKM,
                    BtJ = BtJ$BtJ_L_FPKM,
                    SY = BtSY$SY_L_FPKM,
                    BtSY = BtSY$BtSY_L_FPKM)
# blue模块导入

gene2Module <- read.delim("/Volumes/FileManage/0660Drive/02.heterosis_project/08133BtGroup/03.WGCNA/leaf_result/leaf_Gene2module.xls",
                   header = T,
                   sep = "\t")
head(gene2Module)
blue = dplyr::filter(gene2Module,Module == "blue")

data.tmp1 <- dplyr::left_join(blue,clean,by = "GID")

data.plot <- data.frame(row.names = data.tmp1$GID,
                        log10(data.tmp1[,-c(1,2)]+1))

anno <- read.delim("/Volumes/FileManage/0660Drive/02.heterosis_project/08133BtGroup/03.WGCNA/leaf_result/blue_annotation.txt",
                   header = T,
                   sep = "\t")
head(anno)
type <- unique(anno$Type)
annotation_row = data.frame(row.names = anno$GID,
                            Type = factor(anno$Type,levels = type))

library(pheatmap)

# pdf("Bt.leaf.blue.pdf", width = 5,height = 5)
pheatmap(data.plot, scale = "row",
         show_rownames = F,
         color = colorRampPalette(c("blue", "white", "red"))(50),
         annotation_row = annotation_row,cutree_rows = 4)
# dev.off()

